/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nickssnmp;

import Model.IfTableRfc1213;
import java.math.BigInteger;
import java.text.DecimalFormat;
import javax.persistence.Query;
import javax.swing.JFrame;

/**
 *
 * @author Nikolaos
 */
public class Report2_1 extends javax.swing.JPanel {

    SnmpUtil snmpUtil = null;    
    private JFrame parentFrame;
    private boolean accessDB = false;    
    /**
     * Creates new form Report1
     */
    public Report2_1() {
        initComponents();        
    }

    public Report2_1(JFrame parentFrame, SnmpUtil snmpUtil, boolean accessDB) {
        this.parentFrame = parentFrame;
        this.snmpUtil = snmpUtil;        
        this.accessDB = accessDB;
        initComponents();          
        
        report();        
        
        //tblIfTable.setModel(getTableModel());
    }
    private void report(){
        
        String result = null;
        float up,down,testing; 
        
        String[] arr = new String[22];
        for(int i = 1; i<23 ; i++)
        {
            arr[i-1] = "1.3.6.1.2.1.2.2.1."+i;
        }                                   
        if(accessDB)
        {
            snmpUtil.insertIfTableRFC1213IntoDB(em,snmpUtil.snmpGetTable(arr));
        }                
        
        IfTableRfc1213 face1;        
        
        Query query = em.createNamedQuery("IfTableRfc1213.findMostActiveInterfaces");
        face1 =(IfTableRfc1213) query.getResultList().get(0);
        
        txtMostActiveDescr.setText(face1.getIfDescr());               
        txtInDisc.setText(face1.getIfInDiscards()+"");
        txtOutDisc.setText(face1.getIfOutDiscards()+"");
        
        BigInteger bi1,bi2,bi3;
        
        bi1 = face1.getIfInNucastPkts() == null ? new BigInteger("0") : face1.getIfInNucastPkts();
        bi2 = face1.getIfInUcastPkts() == null ? new BigInteger("0") : face1.getIfInUcastPkts();        
        bi3 = bi1.divide(bi1.add(bi2));                                        
        txtPercNUUIn.setText( bi3.multiply(new BigInteger("100")) +" % ");
        
        bi1 = face1.getIfOutNucastPkts() == null ? new BigInteger("0") : face1.getIfOutNucastPkts();
        bi2 = face1.getIfOutUcastPkts() == null ? new BigInteger("0") : face1.getIfOutUcastPkts();        
        bi3 = bi1.divide(bi1.add(bi2));                                        
        txtPercNUUOut.setText( bi3.multiply(new BigInteger("100")) +" % ");
        
        bi1 = face1.getIfInErrors()== null ? new BigInteger("0") : face1.getIfInErrors();
        bi2 = (face1.getIfInUcastPkts() == null ? new BigInteger("0") : face1.getIfInUcastPkts()).add(
               face1.getIfInNucastPkts() == null ? new BigInteger("0") : face1.getIfInNucastPkts() );        
        bi3 = bi1.divide(bi2);                                        
        txtInRejected.setText( bi3.multiply(new BigInteger("100")) +" % ");
        
        bi1 = face1.getIfOutErrors()== null ? new BigInteger("0") : face1.getIfOutErrors();
        bi2 = (face1.getIfOutUcastPkts() == null ? new BigInteger("0") : face1.getIfOutUcastPkts()).add(
               face1.getIfOutNucastPkts() == null ? new BigInteger("0") : face1.getIfOutNucastPkts() );        
        bi3 = bi1.divide(bi2);                                        
        txtOutRejected.setText( bi3.multiply(new BigInteger("100")) +" % ");
        
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        em = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("NicksSNMPPU").createEntityManager();
        jLabel1 = new javax.swing.JLabel();
        txtMostActiveDescr = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtPercNUUIn = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtPercNUUOut = new javax.swing.JTextField();
        txtOutDisc = new javax.swing.JTextField();
        txtInDisc = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtInRejected = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtOutRejected = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtInRejRate = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtOutRejRate = new javax.swing.JTextField();

        setMinimumSize(new java.awt.Dimension(59, 20));

        jLabel1.setText("Most active interface:");

        txtMostActiveDescr.setText("jTextField1");

        jLabel2.setText("1. Discarded Pakets (no errors) IN:");

        jLabel3.setText("OUT:");

        jLabel4.setText("2. Percentage of NU pkts against U Pkts IN:");
        jLabel4.setToolTipText("");

        txtPercNUUIn.setText("jTextField1");

        jLabel5.setText("OUT:");

        txtPercNUUOut.setText("jTextField1");

        txtOutDisc.setText("jTextField1");

        txtInDisc.setText("jTextField1");

        jLabel6.setText("3. Percentage of pkt rejection IN:");

        txtInRejected.setText("jTextField1");

        jLabel7.setText("OUT:");

        txtOutRejected.setText("jTextField2");

        jLabel8.setText("4. Rejection Rate IN:");

        txtInRejRate.setText("jTextField1");

        jLabel9.setText("OUT:");

        txtOutRejRate.setText("jTextField2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtMostActiveDescr, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtInDisc, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtOutDisc))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPercNUUIn))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtInRejected)
                            .addComponent(txtInRejRate))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPercNUUOut, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtOutRejected))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtOutRejRate)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtMostActiveDescr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtOutDisc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtInDisc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtPercNUUIn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(txtPercNUUOut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtInRejected, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(txtOutRejected, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtInRejRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(txtOutRejRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager em;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField txtInDisc;
    private javax.swing.JTextField txtInRejRate;
    private javax.swing.JTextField txtInRejected;
    private javax.swing.JTextField txtMostActiveDescr;
    private javax.swing.JTextField txtOutDisc;
    private javax.swing.JTextField txtOutRejRate;
    private javax.swing.JTextField txtOutRejected;
    private javax.swing.JTextField txtPercNUUIn;
    private javax.swing.JTextField txtPercNUUOut;
    // End of variables declaration//GEN-END:variables
}
